package com.cheer.controller;

import com.cheer.param.ReferenceFileDownParam;
import com.cheer.param.ReferenceInOrUpParam;
import com.cheer.security.UserInfoHolder;
import com.cheer.service.ReferenceFileService;
import com.cheer.vo.DocumentVO;
import com.cheer.vo.OrganizationTreeVO;
import com.cheer.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


/**
 * 台账文档表
 *
 * @author chufangzheng
 * @email 1280251739@qq.com
 * @date 2022-02-16 08:58:00
 */
@Api(tags = "ReferenceFileController", description = "参评文件")
@RestController
@RequestMapping("referencefile")
public class ReferenceFileController {

    @Autowired
    private ReferenceFileService referenceFileService;

    @Autowired
    private UserInfoHolder userInfoHolder;

    @PostMapping("/upload")
    @ApiOperation(value = "参评文件上传", notes="1.推荐表 2.事迹材料 3.佐证图片")
    public Result<DocumentVO> upload(MultipartFile file, Integer fileType) throws IOException {
        DocumentVO documentVO = referenceFileService.upload(userInfoHolder.getAccountId(), file, fileType);
        return Result.success(documentVO);
    }

    @PostMapping("/down")
    @ApiOperation("参评信息下载")
    public Result<String> down(@RequestBody ReferenceFileDownParam referenceFileDownParam) {
        String urlFilePath = referenceFileService.down(referenceFileDownParam);
        return Result.success(urlFilePath);
    }

    @ApiOperation(value = "推荐表预览", notes = "id ")
    @GetMapping("/preview")
    public void preview(HttpServletResponse response, Long id){

        referenceFileService.preview(response, id);
    }

    @ApiOperation(value = "推荐表上传", notes = "id ")
    @GetMapping("/upload/recommend")
    public Result uploadRecommend(String fileUrl, Long id){
        referenceFileService.uploadRecommend(fileUrl, id);
        return Result.success();
    }



}
